import axios from "axios"
import type { InternalAxiosRequestConfig, AxiosResponse } from "axios"
import { useStore } from "../piniaStore"
const $piniaStore = useStore()
const service = axios.create({
    baseURL: "http://118.178.238.19:3001/admin"
})
// 请求拦截器
service.interceptors.request.use((config: InternalAxiosRequestConfig) => {
    let token = sessionStorage.getItem("token")
    if (token) {
        config.headers.token = token
    }

    $piniaStore.changeShowLoading(true)

    return config
})
// 响应拦截器
service.interceptors.response.use((res: AxiosResponse) => {

    $piniaStore.changeShowLoading(false)

    return res
})

export default service